package com.globalwave.filemanage.entity;

import java.io.File;
import java.sql.Timestamp;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.GenericGenerator;

import com.globalwave.common.C;
import com.globalwave.filemanage.FMCodeHelper;



/**
 *@Transient
 *@author Virgil.Chan
 */
@Entity
@Table(name = "FM_DOCUMENT")
public class Document  {

    @Id
    //@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="increment")
    //@GenericGenerator(name="FM_DOCUMENT_SEQ", strategy = "increment")
    private Long document_id ;
    private Long folder_id ; 
    private String name_ ; 
    private Long size_ ; 
    private String title_ ; 
    private Integer version_ ; 
    private String status_ ; 
    private String type_ ;
    private String author_ ;
    private Timestamp published_on ; 
    private Long published_by ; 
    private Timestamp created_on ;
    private Long created_by ;
    private Timestamp updated_on ;
    private Long updated_by ;
    private Timestamp deleted_on ;
    private Long deleted_by ;
    private String locale_ ;
    
    private Integer indexed_ ;
    
    @Transient
    private File content_ ;
    
    @Transient
    private String summary_ ;
    
	public Long getDocument_id() {
		return document_id;
	}
	public void setDocument_id(Long document_id) {
		this.document_id = document_id;
	}
	public Long getFolder_id() {
		return folder_id;
	}
	public void setFolder_id(Long folder_id) {
		this.folder_id = folder_id;
	}
	public String getName_() {
		return name_;
	}
	public void setName_(String name_) {
		this.name_ = name_;
	}
	public Long getSize_() {
		return size_;
	}
	public void setSize_(Long size_) {
		this.size_ = size_;
	}
	public String getTitle_() {
		return title_;
	}
	public void setTitle_(String title_) {
		this.title_ = title_;
	}
	public Integer getVersion_() {
		return version_;
	}
	public void setVersion_(Integer version_) {
		this.version_ = version_;
	}
	public String getStatus_() {
		return status_;
	}
	public void setStatus_(String status_) {
		this.status_ = status_;
	}
	public String getType_() {
		return type_;
	}
	public void setType_(String type_) {
		this.type_ = type_;
	}
	public Timestamp getPublished_on() {
		return published_on;
	}
	public void setPublished_on(Timestamp published_on) {
		this.published_on = published_on;
	}
	public Long getPublished_by() {
		return published_by;
	}
	public void setPublished_by(Long published_by) {
		this.published_by = published_by;
	}
	public Timestamp getCreated_on() {
		return created_on;
	}
	public void setCreated_on(Timestamp created_on) {
		this.created_on = created_on;
	}
	public Long getCreated_by() {
		return created_by;
	}
	public void setCreated_by(Long created_by) {
		this.created_by = created_by;
	}
	public Timestamp getUpdated_on() {
		return updated_on;
	}
	public void setUpdated_on(Timestamp updated_on) {
		this.updated_on = updated_on;
	}
	public Long getUpdated_by() {
		return updated_by;
	}
	public void setUpdated_by(Long updated_by) {
		this.updated_by = updated_by;
	}
	public Timestamp getDeleted_on() {
		return deleted_on;
	}
	public void setDeleted_on(Timestamp deleted_on) {
		this.deleted_on = deleted_on;
	}
	public Long getDeleted_by() {
		return deleted_by;
	}
	public void setDeleted_by(Long deleted_by) {
		this.deleted_by = deleted_by;
	}
	public File getContent_() {
		return content_;
	}
	public void setContent_(File content_) {
		this.content_ = content_;
	}
	public String getAuthor_() {
		return author_;
	}
	public void setAuthor_(String author_) {
		this.author_ = author_;
	}
	public String getLocale_() {
		if (StringUtils.isEmpty(locale_)) {
			return C.LOCALE_DEFAULT ;
		}
		return locale_;
	}
	public void setLocale_(String locale_) {
		this.locale_ = locale_;
	}
	
	/**
	 * 是否已经为文档建索引
	 * 
	 * 0=未建Index;1=已建Index
	 * @return
	 */
    public Integer getIndexed_() {
		return indexed_;
	}
    public void setIndexed_(Integer indexed_) {
		this.indexed_ = indexed_;
	}
    public void setSummary_(String summary_) {
		this.summary_ = summary_;
	}
    public String getSummary_() {
		return summary_;
	}
    
    public String getFolderPath() {
    	return FMCodeHelper.getWebConfig("realPath") 
		+ FMCodeHelper.getUploadDir() + "/" + String.valueOf((10000 + this.document_id%10000)/100) ;
    }
}
